package com.itheima;

import static com.itheima.Java_05.split;

public class Java_06 {
    public static void main(String[] args) {
        //案例练习：开发一个加密程序
        System.out.println("加密结果是："+password(8346));
    }
    public static String password(int number){
        //拆分数字
        int[] numbers = split(number);
        for (int i = 0; i < numbers.length; i++) {
            numbers[i] = (numbers[i] + 5) % 10;
        }
        reserve(numbers);
        String data = "";
        for (int i = 0; i < numbers.length; i++) {
            data += numbers[i];
        }
        return data;
    }
    //反转数组
    public static void reserve (int[] numbers){
        for (int i = 0,j = numbers.length-1; i < j; i++,j--) {
            int temp = numbers[j];
            numbers[j] = numbers[i];
            numbers[i] = temp;
        }
    }
    //拆分成一个个的数字
    public static int[] split(int number) {
        int[] numbers = new int[4];
        numbers[0] = number / 1000;
        numbers[1] = (number / 100) % 10;
        numbers[2] = (number / 10) % 10;
        numbers[3] = (number % 10);
         return numbers;
    }

}
